package com.example.finalassessment.controller;

import com.example.finalassessment.dto.CategoryProductCountDTO;
import com.example.finalassessment.model.Category;
import com.example.finalassessment.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author funny_chao
 * @since 2024-12-09
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private ICategoryService categoryService;

    // 获取所有分类及商品数量
    @GetMapping("/count")
    public List<CategoryProductCountDTO> getCategoryProductCount() {
        return categoryService.getCategoryProductCount();
    }

    @GetMapping("/all")
    public ResponseEntity<List<Category>> getAllProducts() {
        List<Category> category = categoryService.list();
        return ResponseEntity.ok(category);
    }

}
